﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Data;
using Labthink.PCSoft.UniversalHost4.Utility;

namespace Labthink.PCSoft.UniversalHost4.Instrument.Converters
{
    [ValueConversion(typeof(int), typeof(double))]
    public class IntervalValueConverter:IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var ds = parameter as List<double>;
            if (ds == null) return 0;
            return ds[value.ToInt() - 1];
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var ds = parameter as List<double>;
            if (ds == null) return 0;
            return ds.IndexOf(value.ToDouble()) + 1;
        }
    }
}
